<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品名称">
              <a-input placeholder="请输入商品名称" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商家名称">
              <a-input placeholder="请输入商家名称" v-model="queryParam.shopName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-if="name!='B2B2C'" @click="handleAdd1" type="primary" icon="plus">新增自营商品</a-button>
      <a-divider v-if="sysMode==3||sysMode==4" type="vertical" />
      <a-button v-if="sysMode==3||sysMode==4" @click="handleAdd2" type="primary" icon="plus">新增店铺商品</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination"
        :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-if="record.activeStatus==1" @click="handleEdit(record)">编辑</a>
          <a-divider v-if="record.activeStatus==1" type="vertical" />
          <a v-if="record.isCommission == 1" @click="discountEdit(record)">分佣配置</a>
          <a-divider v-if="record.isCommission == 1" type="vertical" />
          <a @click="handleDetail(record)">查看</a>
          <a-divider type="vertical" />
          <a-popconfirm v-if="record.activeStatus!=3&&record.isExpire==0" title="确定禁用吗?" @confirm="() => handleStop(record.id)">
            <a>禁用</a>
          </a-popconfirm>
          <a v-else-if="record.isExpire==1" style="color:#999999;">已禁用</a>
          <a v-else style="color:#999999;">已过期</a>
          <a-divider type="vertical" />
          <a-popconfirm v-if="record.activeStatus!=2||record.isExpire==1" title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <msms-good-modal ref="modalForm" @ok="modalFormOk"></msms-good-modal>
    <gms-range-info ref="rangeDiscount"></gms-range-info>
  </a-card>
</template>

<script>
import { putAction, getAction, postAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/MyJeecgListMixin'
import MsmsGoodModal from './modules/MsmsGoodModal'
import GmsRangeInfo from '@/views/gospel/mallBase/good/modules/GmsRangeInfo'

export default {
  name: 'MsmsGoodList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    MsmsGoodModal,
    GmsRangeInfo
  },
  data () {
    return {
      name: process.env.VUE_APP_PATTERN,
      description: '秒杀商品管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        // {
        //   title: '秒杀场次',
        //   align: "center",
        //   dataIndex: 'sceneId'
        // },
        {
          title: '商品图片',
          align: "center",
          dataIndex: 'imgUrl',
          scopedSlots: { customRender: 'imgSlot' }
        },
        {
          title: '商品名称',
          align: "center",
          dataIndex: 'title'
        },
        {
          title: '商家名称',
          align: "center",
          dataIndex: 'shopName'
        },
        {
          title: '秒杀价',
          align: "center",
          dataIndex: 'price'
        },
        {
          title: '实付金额',
          align: "center",
          dataIndex: 'payAmount',
          customRender: function (text) {
            return text ? text : 0
          }
        },
        {
          title: '付款订单数',
          align: "center",
          dataIndex: 'payOrderNum'
        },
        {
          title: '付款人数',
          align: "center",
          dataIndex: 'payUserNum'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/mallPlus/msmsGood/list",
        delete: "/mallPlus/msmsGood/delete",
        deleteBatch: "/mallPlus/msmsGood/deleteBatch",
        exportXlsUrl: "/mallPlus/msmsGood/exportXls",
        importExcelUrl: "mallPlus/msmsGood/importExcel",

      },
      dictOptions: {},
    }
  },
  created () {
    if (this.$route.query.id) {
      this.queryParam.sceneId = this.$route.query.id
    }
    this.loadData()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleAdd1: function () {
      this.$refs.modalForm.add(1, this.queryParam.sceneId)
      this.$refs.modalForm.title = "新增自营商品"
      this.$refs.modalForm.disableSubmit = false
    },
    handleAdd2: function () {
      this.$refs.modalForm.add(2, this.queryParam.sceneId)
      this.$refs.modalForm.title = "新增店铺商品"
      this.$refs.modalForm.disableSubmit = false
    },
    //禁用
    handleStop: function (id) {
      var that = this
      putAction("/mallPlus/msmsGood/stop", { id: id }).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    //分佣配置
    discountEdit (record) {
      let self = this
      self.$refs.rangeDiscount.visible = true;
      self.$refs.rangeDiscount.itemId = record.id;
      self.$refs.rangeDiscount.itemType = 2;
      self.$refs.rangeDiscount.open()
    },
    //开启
    handleStart: function (id) {
      var that = this
      putAction("/mallPlus/msmsGood/start", { id: id }).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    initDictConfig () {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>